import wepy from 'wepy'

export default class extends wepy.mixin {
  config = {}

  data = {
    // 楼层数据
    floorList:[],
    // 分类数据
    cateList: [],
    // 轮播数据 -
    swiperList: [],
    autoplay: true,
    interval: 2000,
    duration: 1000
  }

  methods = {

    goGoodsDetail(val){
      //console.log('000')
      wepy.navigateTo({
        url:'/pages/goods_list?goods_id='+val
      })
    },
    goGoodsList(item){
        wepy.navigateTo({
          url:'/pages/goods_list'
        })
    }
  }

  onLoad() {
    this.getSwiperData()
    this.getCateData()
    this.getFloorData()
    
  }
  onShow(){
    // 解决返回tabBar显示角标的bug
    this.$parent.renderCartBadge()
  }
  // 获取楼层数据
  async getFloorData(){
    const { data: res } = await wepy.get('/home/floordata')
    if (res.meta.status != 200)
      return wepy.baseToast();
    this.floorList = res.message
    this.$apply()
    //console.log(this.floorList)
  }
  // 获取分类数据
  async getCateData() {
    const { data: res } = await wepy.get('/home/catitems')
    if (res.meta.status != 200)
      return wepy.baseToast();
    this.cateList = res.message
    this.$apply()
    // //console.log(this.cateList)
  }
  // 获取轮播数据
  async getSwiperData() {
  const { data: res } = await wepy.request({
    url: 'https://www.zhengzhicheng.cn/api/public/v1/home/swiperdata',
    methods: 'get',
    data: {}
  })
  if (res.meta.status != 200)
    return wx.showToast({
      title: '获取数据失败',
      icon: 'none',
      duration: 1500
    })
  this.swiperList = res.message
  this.$apply()
  }
}